<template>
  <div class="box">
    <div class="img"><span></span>热搜榜 </div>
    <ul id="hotSearch">
      <li v-for="(item,index) in list" :key="index"> <span>{{index+1}}</span><span id="hot" ref="hot" @click="searchHot(index)">{{item.first}}</span></li>
    </ul>
  </div>
</template>

<script>

import {getHotSearch} from "@/http/api";

export default {
  name: "TopSearch",
  data(){
    return {
      list:[],
      keyword:'',

    }
  },
  created() {
    getHotSearch().then(res=>{
      // console.log(res)
      this.list = res.data.result.hots
    })
  },
  methods : {
    searchHot(index){
      this.keyword = this.$refs.hot[index].innerText
      this.$emit('searchTop',{
        keyword:this.keyword
      })
    },

  }
}
</script>

<style scoped lang="less">
.img {
  position: relative;
  >img {
    position: absolute;
    right: 15px;
    width: 40px;
    height: 40px;
  }
}
  .box {
    margin-bottom: 15px;
    padding: 0 8px;
    >div {
      display: flex;
      align-items: center;
      font-size: 17px;
      font-weight: 600;
      margin: 12px 0;
      >span {
        display: inline-block;
        height: 20px;
        width: 3px;
        background-color: red;
        margin-right: 6px;
      }
    }
    >ul:nth-of-type(1) {
      list-style: none;
      height: 180px;
      display: flex;
      flex-direction: column;
      flex-wrap: wrap;
      background-color: #f0f0f0;
      border-radius: 20px;
      >li {
        padding: 7px 45px 5px 55px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 15px;
        width: 50%;
        font-weight: 600;
        position: relative;
        >span:nth-of-type(1) {
          position: absolute;
          left: 30px;
          top: 8px;
          // padding-right: 20px;
          text-align: center;
          display: inline-block;
          width: 25px;
        }
      }
      >li:nth-of-type(1),
      >li:nth-of-type(2),
      >li:nth-of-type(3) {
        >span:nth-of-type(1) {
          color: red;
          font-weight: 700;
        }
      }
    }
  }
</style>